package com.IODemo;

import java.io.*;
import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2022/06/27/15:47
 * @Description:
 * @Target:
 */
public class noRepeat {
    public static void main(String[] args) throws Exception {
        
        readPath("C:\\Users\\lenovo\\Desktop\\公司业务总结\\sqlTable\\LIST1.TXT");
        
    }


    static void readPath(String pathTxt) throws Exception{
        try {
            FileReader fileReader = new FileReader(pathTxt);
            BufferedReader bf = new BufferedReader(fileReader);
            // 按行读取字符串
            String str;

            while ((str = bf.readLine()) != null) {
//                System.out.println(str);
                String[] split = str.split("\\\\");
                write(read(str),split[split.length-1]);
                
                
            }
            bf.close();
            fileReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    
    
    static String read(String pathTxt) throws Exception{
        HashSet<String> set = new HashSet();
        try {
            FileReader fileReader = new FileReader(pathTxt);
            BufferedReader bf = new BufferedReader(fileReader);
            // 按行读取字符串
            String str;

            while ((str = bf.readLine()) != null) {
                String ss = "";
                for (int i = 0; i < str.length(); i++) {
                    if (check(str.charAt(i))){
                        ss+=str.charAt(i);
                    }else {
                        set.add(ss);
                        ss = "";
                    }
                }
                set.add(ss);
            }
            bf.close();
            fileReader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        String returnString = "";

        for (String s : set) {
            returnString += s + "*";
        }

        return returnString;
    }

    

    static void write(String name,String path){
        path = "C:\\Users\\lenovo\\Desktop\\公司业务总结\\sqlTable\\noRepeat\\"+path;
        File file=new File(path);//录入文件地址
        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        OutputStream os=null;
        try {
            os=new FileOutputStream(file,false);//false覆盖  true 追加
            byte[] b=name.getBytes();
            os.write(b);//写入
            os.close();//关闭流
        } catch ( Exception e) {
            e.printStackTrace();
        }
    }
    
    // check所有字母,数字,_不是就false
    static boolean check(char c){
        if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == '.'){
            return true;
        }else {
            return false;
        }
    }
}
